package com.rock.platform.core;

import java.util.ArrayList;
import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.opensymphony.xwork2.ActionSupport;
import com.rock.platform.util.LoginBean;

public class BaseAction extends ActionSupport {
	private static final long serialVersionUID = -3609342038414736L;

	protected LoginBean loginBean;
	protected String jsonString;
	protected String jsonParameter;
	protected int start;
	protected int limit;
	protected int page;
	protected String sort;
	private SortEntity sortEntity;
	

	public LoginBean getLoginBean() {
		return loginBean;
	}

	public void setLoginBean(LoginBean loginBean) {
		this.loginBean = loginBean;
	}

	public String getJsonParameter() {
		return jsonParameter;
	}

	public void setJsonParameter(String jsonParameter) {
		this.jsonParameter = jsonParameter;
	}
	
	public String getJsonString() {
		return this.jsonString;
	}

	public void setJsonString(String jsonString) {
		this.jsonString = jsonString;
	}

	public int getStart() {
		return this.start;
	}

	public void setStart(int start) {
		this.start = start;
	}

	public int getLimit() {
		return this.limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public String getSort() {
		return sort;
	}

	public void setSort(String sort) {
		this.sort = sort;
	}

	public SortEntity getSortEntity() {
		
		if (sortEntity == null && sort != null )
		{
			try
			{
				JSONArray ja = JSONArray.fromObject(this.sort);
				sortEntity = new SortEntity();
				List<String> propertyList = new ArrayList<String>();
				StringBuffer sbPropertys = new StringBuffer();
				for(int i = 0; i < ja.size(); i++)
				{
					JSONObject jo = ja.getJSONObject(i);
					String pro = jo.getString("property");
					propertyList.add(pro);
					sbPropertys.append(pro);
					sbPropertys.append(",");
					sortEntity.setDirection(jo.getString("direction"));
				}
				sortEntity.setPropertyList(propertyList);
				sortEntity.setSort(sort);
				sbPropertys.delete(sbPropertys.length()-1, sbPropertys.length());
				sortEntity.setPropertys(sbPropertys.toString());
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}
		}
		return sortEntity;
	}

	/*public void setSortEntity(SortEntity sortEntity) {
		this.sortEntity = sortEntity;
	}*/
}